﻿//Added By Dhanapal For AutoComplete DropDown Section in PageWizard.aspx on Dec 7 2010
function getSectionArray() {
    var foo = [];
//    var optins = $('#ctl00_ContentPlaceHolder3_dd_section_name').attr('options');
//    //alert(optins);
//    //alert($('#ctl00_ContentPlaceHolder3_dd_section_name').parent().html());
//    for (var index = 0; index < optins.length; index++) {
//        foo[index] = optins[index].value;
//        alert(optins[index].value);
//    }
    var ind = -1;
    $("#ctl00_ContentPlaceHolder3_dd_section_name > option").each(function() {//changed by sanal to make it compatible with latest jQuery
        ind++;
        foo[ind] = this.value;
    });
    return foo;
}
    
function checkSelectBoxvalue(value) {
    exists = false;
    $('#ctl00_ContentPlaceHolder3_dd_section_name option').each(function () {
        if (this.value == value) {
            exists = true;
            return exists;
        }
    });
    return exists;
}
    
function addTagbind(cond) {
  $("#ctl00_ContentPlaceHolder3_Tags").val(''); //To clear the Existing Values
  $("#ctl00_ContentPlaceHolder3_Tags").autocomplete({
        source: getSectionArray(),
        change: function (event, ui) {

        }
    });
}

/*************Code To fill the DropDownList*********************/

    
function fillCombo() {
 try
 {
    if (document.getElementById("ctl00_ContentPlaceHolder3_hdfDynamicGridId")) {
        var dynamictableid = document.getElementById("ctl00_ContentPlaceHolder3_hdfDynamicGridId").value;
        if (dynamictableid != "") {
            var tableid = dynamictableid;
            var dynamictableid = "ctl00_ContentPlaceHolder3_pagewizard_" + dynamictableid;
            var dynamictableobj = document.getElementById(dynamictableid);
            var dynamictableChildNodes = dynamictableobj.childNodes;
            for (var i = 0; i < dynamictableChildNodes.length; i++) {
                if (dynamictableChildNodes[i].tagName == "TBODY") { //This Gets the Body of the Table Object which holds the row

                    getSectionNameandAppend(dynamictableChildNodes[i], tableid);

                }

            }

        }

    }
  }
  catch(Ex)
  {
  
  }
}
    

function getSectionNameandAppend(tbodyObj, dynTableId) {
    var currpgeId = dynTableId.substring(4, dynTableId.length);
    var rowCnt = 0;
    for (var j = 0; j < tbodyObj.childNodes.length; j++) {
        if (tbodyObj.childNodes[j].tagName == "TR") {
            if (rowCnt > 0) {
                var prefixid = "ctl00_ContentPlaceHolder3_pagewizard_tblgrdDynamictr_";
                var visibleRowCount = tbodyObj.childNodes[j].id.substring(prefixid.length, tbodyObj.childNodes[j].id.length);
                var hdnSectionId = "ctl00_ContentPlaceHolder3_pagewizard_" + currpgeId + "dd_section_name" + visibleRowCount;
                if (document.getElementById(hdnSectionId)) {
                    var secname = document.getElementById(hdnSectionId).value;
                    if (secname != "") {
                        checkandappend(secname);
                    }
                }
                rowCnt++;
            } else {
                rowCnt++;
            }

        }
    }
}
    
function checkandappend(sectionname) {
    var val = checkSelectBoxvalue(sectionname);
    if (val == false) { //if the Value Does not Exists
        //var options = $('#ctl00_ContentPlaceHolder3_dd_section_name').attr('options');
        var options = document.getElementById('ctl00_ContentPlaceHolder3_dd_section_name').options;//changed by sanal to make it compatible with latest jQuery
        options[options.length] = new Option(sectionname, sectionname);
       }

}